﻿namespace PredatorPrey.Library
{
	// Id		: $Id: Cell.cs 39 2009-04-23 21:38:07Z kristof@kristofmattei.be $
	// Date		: $Date: 2009-04-23 21:38:07 +0000 (Thu, 23 Apr 2009) $
	// Author	: $Author: kristof@kristofmattei.be $
	// Revision	: $Revision: 39 $
	/// <summary>
	/// I don't want to use the Point from the .NET framework, it is too expanded
	/// </summary>
	public class Cell
	{
		/// <summary>
		/// X location
		/// </summary>
		public int X { get; set; }

		/// <summary>
		/// Y location
		/// </summary>
		public int Y { get; set; }

		/// <summary>
		/// Type of this cell
		/// </summary>
		public FieldType FieldType { get; private set; }

		public Cell()
		{
		}

		/// <summary>
		/// Construct a cell
		/// </summary>
		/// <param name="x">X location of the cell</param>
		/// <param name="y">Y location of the cell</param>
		/// <param name="fieldType">The type of the cell</param>
		public Cell(int x, int y, FieldType fieldType)
			: this() 
		{
			this.X = x;
			this.Y = y;
			this.FieldType = fieldType;
		}

		#region Overrides

		/// <summary>
		/// Checks if this cell is equal to <paramref name="obj"/>
		/// </summary>
		/// <param name="obj">The object to match agains</param>
		/// <returns>True if they are equal, false if not</returns>
		public override bool Equals(object obj)
		{
			return (obj is Cell) ? this.Equals((Cell)obj) : false;
		}

		/// <summary>
		/// Get a uniqe identifier of this cell
		/// </summary>
		/// <returns>An unique number</returns>
		public override int GetHashCode()
		{
			return this.X ^ this.Y ^ (int)this.FieldType;
		}

		/// <summary>
		/// Checks if this cell equals another <paramref name="cell"/>
		/// </summary>
		/// <param name="cell">The cell to match against</param>
		/// <returns>True if they are equal, false if not</returns>
		public bool Equals(Cell cell)
		{
			return (cell.X == this.X && cell.Y == this.Y && this.FieldType == cell.FieldType) ? true : false;
		}

		/// <summary>
		/// Checks if two cells are NOT equal
		/// </summary>
		/// <param name="cell1">The first cell</param>
		/// <param name="cell2">The second cell</param>
		/// <returns>False if they are equal, true if they are not equal </returns>
		public static bool operator ==(Cell cell1, Cell cell2)
		{
			return cell1.Equals(cell2);
		}

		/// <summary>
		/// Checks if two cells are NOT equal
		/// </summary>
		/// <param name="cell1">The first cell</param>
		/// <param name="cell2">The second cell</param>
		/// <returns>False if they are equal, true if they are not equal </returns>
		public static bool operator !=(Cell cell1, Cell cell2)
		{
			return !cell1.Equals(cell2);
		}

		/// <summary>
		/// Creates a String which identifies the object
		/// </summary>
		/// <returns>A string with the object's values</returns>
		public override string ToString()
		{
			return string.Format("({0}, {1}), FieldType = {2}", this.X, this.Y, this.FieldType);
		}

		#endregion
	}
}
